package com.gzist.elderlyserviceplatform.controller.admin;

import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.VideoDto;
import com.gzist.elderlyserviceplatform.entity.po.Video;
import com.gzist.elderlyserviceplatform.service.VideoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 视频管理表
 */
@RestController
@Tag(name = "视频管理")
@RequestMapping("/api/admin/video")
@RequiredArgsConstructor
public class VideoControllerA {

    private final VideoService videoService;

    @PostMapping("/add")
    @Operation(summary = "视频添加")
    public Result add(
            @RequestBody
            @Parameter(description = "视频信息") Video video
    ) {
        return Result.success(videoService.save(video), "添加成功");
    }

    @PostMapping("/querylist")
    @Operation(summary = "视频列表")
    public Result queryList(
            @RequestBody
            @Parameter(description = "查询参数") VideoDto videoDto
    ) {
        return Result.success(videoService.queryList(videoDto), "查询成功");
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "根据id删除视频")
    public Result delete(
            @PathVariable("id")
            @Parameter(description = "视频主键id") String id
    ) {
        return Result.success(videoService.removeById(id), "删除成功");
    }

    @PostMapping("/update")
    @Operation(summary = "修改单个视频")
    public Result update(
            @RequestBody
            @Parameter(description = "视频信息") Video video
    ) {
        return Result.success(videoService.update(video), "修改成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除视频", description = "Video")
    public Result batchDelete(
            @RequestBody
            @Parameter(description = "视频主键id集") String[] ids
    ) {
        videoService.removeByIds(Arrays.asList(ids));
        return Result.success("删除成功!");
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "视频详情")
    public Result<Video> query(
            @PathVariable
            @Parameter(description = "视频主键id") String id
    ) {
        return Result.success(videoService.getById(id), "查询成功");
    }
}